<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="css/uploadify.css" />
</head>
<body>
	<div>
		<form action="">
		<table>
			<tr>
				<div id="fileQueue"></div>
				<td width="45%"><input type="file" name="foodPic" id="addPic" /></td>
				<div id="imgContainer"></div>
			</tr>
		</table>
		<input type="hidden" name="upload_org_code_name" id="upload_org_code_name" />
		<button id="uploadBtn">开始上传</button>
		</form>
	</div>
	<script src="js/jquery.min.js"></script>
	<script src="js/jquery.uploadify.min.js"></script>
	<script>
		$(document).ready(function() {
			$("#addPic").uploadify(
				{
					'height' : 27,
					'width' : 80,
					'buttonText' : '选择图片',
					'swf' : 'css/uploadify.swf',
					'uploader' : 'http://localhost:8080/AsyncUploadTestServlet',
					'queueID' : 'fileQueue',
					'auto' : false,
					'multi' : true,
					'removeCompleted' : false,
					'cancelImg' : 'uploadify-cancel.png',
					'fileTypeExts' : '*.jpg;*.jpge;*.gif;*.png',
					'fileSizeLimit' : '2MB',
					'fileObjName' : 'foodPic',
					'onUploadSuccess' : function(file, data, response) {
						$('#' + file.id).find('.data').html('');
						$("#upload_org_code_name").val(data);

						// var img = $("<img></img>");

						// img.attr("src", "PicServlet?picName=" + data);
						// img.appendTo($("#imgContainer"));
						alert("上传成功" + data)
					},
					//加上此句会重写onSelectError方法【需要重写的事件】
					'overrideEvents' : [ 'onSelectError', 'onDialogClose' ],
					//返回一个错误，选择文件的时候触发
					'onSelectError' : function(file, errorCode, errorMsg) {
						switch (errorCode) {
						case -110:
							alert("文件 ["
									+ file.name
									+ "] 大小超出系统限制的"
									+ jQuery('#upload_org_code').uploadify(
											'settings', 'fileSizeLimit')
									+ "大小！");
							break;
						case -120:
							alert("文件 [" + file.name + "] 大小异常！");
							break;
						case -130:
							alert("文件 [" + file.name + "] 类型不正确！");
							break;
						}
					},
				});
			$("#uploadBtn").click(function() {
				$("#addPic").uploadify("upload", "*");
			});
		});
	</script>
</body>
</html>